from bs4 import BeautifulSoup
import os, csv

for year in range(1984, 2018):
	wr = open("D:\\KIPRIS\\Family\\Family{}.xml".format(year), "w", encoding = "utf-8")
	folder = "D:\\KIPRIS\\Family\\{}".format(year)
	files = os.listdir(folder)
	for file in files:
		appnum = file[:-4]
		file_dir =  "D:\\KIPRIS\\Family\\{}\\".format(year) + file
		xml_file = open(file_dir, "r", encoding = "utf-8")
		xml = xml_file.read()
		soup = BeautifulSoup(xml, "xml")
		apn = soup.find("applicationNumber")
		if apn != None:
			print(apn.text)
			original_tag = soup.response
			new_tag = soup.new_tag("appnum")
			original_tag.append(new_tag)
			new_tag.string = appnum
			xml = soup.prettify()
			xml = xml + "\n"
			wr.write(xml)